#include "mymap.h"

void myMap(Mat src, Mat &dest, int meth)
{
	dest = Mat(src.size(), src.type());
	int rows = src.rows;
	int cols = src.cols;
	Mat xMap(src.size(),CV_32FC1);
	Mat yMap(src.size(), CV_32FC1);
	switch (meth)
	{
	case 0: {
		for (int i = 0; i < rows; i++)
		{
			float* ptrX = xMap.ptr<float>(i);
			float* ptrY = yMap.ptr<float>(i);
			for (int j = 0; j < cols; j++) {

				ptrX[j] = cols - j;
				ptrY[j] =i ;
			}
		}
	}break;

	case 1: {
		for (int i = 0; i < rows; i++)
		{
			float* ptrX = xMap.ptr<float>(i);
			float* ptrY = yMap.ptr<float>(i);
			for (int j = 0; j < cols; j++) {

				ptrX[j] = j;
				ptrY[j] = rows - i;
			}
		}
	}break;
	case 2: {
		for (int i = 0; i < rows; i++)
		{
			float* ptrX = xMap.ptr<float>(i);
			float* ptrY = yMap.ptr<float>(i);
			for (int j = 0; j < cols; j++) {

				ptrX[j] = cols - j;
				ptrY[j] = rows - i;
			}
		}
	}break;
	
	case 3: {
		for (int i = 0; i < rows; i++)
		{
			float* ptrX = xMap.ptr<float>(i);
			float* ptrY = yMap.ptr<float>(i);
			for (int j = 0; j < cols; j++) {

				if (j > cols * 0.25 && j < cols * 0.75 && i > rows * 0.25 && i < rows * 0.75)
				{
					ptrX[j] = 2 * (j - cols * 0.25) ;
					ptrY[j] = 2 * (i - rows * 0.25) ;
				}
				else
				{
					ptrX[j] = 0;
					ptrY[j] = 0;
				}
			}
		}
	} break;





	}
	remap(src, dest, xMap, yMap, INTER_LINEAR, 0, Scalar(0, 0, 255));
	
}
